package com.colin.app.broadcast;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.p2p.WifiP2pConfig;
import android.net.wifi.p2p.WifiP2pManager;

import com.colin.library.help.LogHelp;

/**
 * Created by Colin on 2017/2/20.
 */

public class WiFiDirectReceiver extends BroadcastReceiver {

    private WifiP2pManager mManager;
    private WifiP2pManager.Channel mChannel;
    private Activity mActivity;
    private WifiP2pManager.PeerListListener mListener;
    private WifiP2pConfig mConfig = new WifiP2pConfig();

    public WiFiDirectReceiver() {
    }

    public WiFiDirectReceiver(WifiP2pManager manager, WifiP2pManager.Channel channel, Activity activity) {
        this.mManager = manager;
        this.mChannel = channel;
        this.mActivity = activity;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        LogHelp.e("wifi direct action: " + action);
        if (action.equals(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION)) {
            LogHelp.e("Wi-Fi直连的状态发生变化时触发");
            int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
            if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
                LogHelp.e("打开WiFi");
            } else if (state == WifiP2pManager.WIFI_P2P_STATE_DISABLED) {
                LogHelp.e("关闭WiFi");
            }
        } else if (action.equals(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION)) {
            LogHelp.e("在调用discoverPeers()时触发，可以调用 requestPeers() 方法更新设备列表");
        } else if (action.equals(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION)) {
            LogHelp.e("当设备的Wi-Fi的连接状态发生变化时触发");
        } else if (action.equals(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION)) {
            LogHelp.e("Wi-Fi直连的设备的详细信息发生变化时触发创建Wi-Fi直连的应用");
        }
    }
}
